package jumpInstructions;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import main.MIPSSimulator;

public class Bltz extends MIPSJumpInstruction {
	public Bltz(String input) throws FileNotFoundException, IOException {
		myRecognizedRegisters.load(new FileInputStream(new File(
				"recognizedRegisters.properties")));
		myRegisterOne = myRecognizedRegisters.getProperty(input
				.substring(6, 11));
		myName = "bltz";
		parseImmediate(input);

		if (!MIPSSimulator.myLabelLocations
				.containsKey(MIPSSimulator.currentInstructionLocation
						+ myTarget)) {
			myLabelName = "label" + MIPSSimulator.myLabelCounter;
			MIPSSimulator.myLabelLocations.put(
					MIPSSimulator.currentInstructionLocation + myTarget,
					myLabelName);
			MIPSSimulator.myLabelCounter++;
		} else {
			myLabelName = MIPSSimulator.myLabelLocations
					.get(MIPSSimulator.currentInstructionLocation + myTarget);
		}
	}

	public String toString() {
		return myName + " " + myRegisterOne + ", "
				+ myLabelName;
	}

	@Override
	public void execute() {
		if (MIPSSimulator.myRegisters.get(myRegisterOne) < 0) {
			MIPSSimulator.PC += myTarget;
		}
	}
}
